using Microsoft.AspNetCore.Mvc;
using ZR.Model.Dto;
using ZR.Model.Business;
using ZR.Service.Business.IBusinessService;
using ZR.Admin.WebApi.Filters;

//创建时间：2023-12-22
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 产品管理
    /// </summary>
    [Verify]
    [Route("business/Sales")]
    public class SalesController : BaseController
    {
        /// <summary>
        /// 产品管理接口
        /// </summary>
        private readonly ISalesService _SalesService;

        public SalesController(ISalesService SalesService)
        {
            _SalesService = SalesService;
        }

        /// <summary>
        /// 查询产品管理列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "sales:list")]
        public IActionResult QuerySales([FromQuery] SalesQueryDto parm)
        {
            var response = _SalesService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询产品管理详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "sales:query")]
        public IActionResult GetSales(int Id)
        {
            var response = _SalesService.GetInfo(Id);
            
            var info = response.Adapt<SalesDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加产品管理
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "sales:add")]
        [Log(Title = "产品管理", BusinessType = BusinessType.INSERT)]
        public IActionResult AddSales([FromBody] SalesDto parm)
        {
            var modal = parm.Adapt<Sales>().ToCreate(HttpContext);

            var response = _SalesService.AddSales(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新产品管理
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "sales:edit")]
        [Log(Title = "产品管理", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateSales([FromBody] SalesDto parm)
        {
            var modal = parm.Adapt<Sales>().ToUpdate(HttpContext);
            var response = _SalesService.UpdateSales(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除产品管理
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "sales:delete")]
        [Log(Title = "产品管理", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteSales([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_SalesService.Delete(idArr));
        }

    }
}